I have generated the code to solve the expression which is written in the textbox. Please review it and let us know if any information is required.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace
WindowsFormsApplication2 { publicpartialclassForm1 : Form { public Form1() { InitializeComponent(); } privateobject
CalculateExpression(string eqn) { string test = eqn.Replace("{", "(").Replace("}", ")").Replace("[", "(").Replace("]", ")"); string test2 = test.Replace(")", ")*").Replace("(", "*("); string test3 = test2.Replace("**", "*"); char[] ch = newchar[100]; ch = test3.ToCharArray(); int a = test3.Length; a = a - 1; if (ch[a] == '*') { ch[a] = ' '; } if (ch[0] == '*') { ch[0] = ' '; } string test4 = newstring(ch); string test5 = test4.Replace("/*", "/").Replace("*/", "/").Replace("+*", "+").Replace("*+", "+").Replace("-*", "-").Replace("*-", "*").Replace("(*", "(").Replace("*)", ")").Replace("**", "*"); eqn = test5.Trim(); DataTable dt = newDataTable(); var result = dt.Compute(eqn, string.Empty); return result; } privatevoid Form1_Load(object sender, EventArgs e) { } privatevoid button1_Click(object sender, EventArgs e) { try { string result = Convert.ToString(CalculateExpression(textBox1.Text.Trim())); textBox2.Text = result; textBox2.ForeColor =
Color.Blue; } catch (Exception ex) { textBox2.Text = "Please
Review your Expression" + ex.Message.ToString(); textBox2.ForeColor = Color.Red; } } } }
Liked By
Write Answer
How to create an application to solve an expression
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Abhishek Srivasatava
28-Nov-2016Hi Simond,
I have generated the code to solve the expression which is written in the textbox. Please review it and let us know if any information is required.